// compile: g++ -o thread_pool thread_pool.cc -std=c++11
// run: ./thread_pool
#include "thread_pool.h"

#include <atomic>
#include <chrono>
using namespace std;

using namespace std::chrono_literals;

class MyTask : public Task {
 public:
  void Run() override;
};
void MyTask::Run() {
  using namespace std::chrono_literals;
  std::cout << "thread " << std::this_thread::get_id() << " begin" << std::endl;
  std::this_thread::sleep_for(std::chrono::seconds(5s));
  std::cout << "thread " << std::this_thread::get_id() << " end" << std::endl;
}
void Test1() {
  ThreadPool pool(256);
  pool.SetThreadNum(3);
  pool.Start();

  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());
  pool.AddTask(std::make_shared<MyTask>());

  cin.get();
}
void Test2() {}
int main() {
  Test1();
  Test2();
  return 0;
}
